package com.jingdianjichi.oss.config;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.jingdianjichi.oss.adapter.StorageAdapter;
import com.jingdianjichi.oss.adapter.impl.AliStorageAdapter;
import com.jingdianjichi.oss.adapter.impl.MinioStorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 适配器模式负责 选择存储服务
 */
@Configuration
@RefreshScope
public class StorageConfig {

    @Value(value ="${storage.service.type}")
    private String type;


    @Bean
    @RefreshScope
    public StorageAdapter storageService() {
        if ("minio".equals(type)) {
            return new MinioStorageAdapter();
        }
        if ("ali".equals(type)) {
            return new AliStorageAdapter();
        }
        return null;
    }
}
